<?php
if (!defined('IN_MEDIA')) die("Hacking attempt");
if(is_numeric($id)) {
	$sql 								= "SELECT * FROM ".$tb_prefix."singer WHERE singer_id = $id";
	$query 								= $mysql->query($sql);
		if($mysql->num_rows($query)) {
				//////// INFO SINGERS /////////
				$row 					= $mysql->fetch_array($query);
				$singer_ID				= $row['singer_id'];
				$singer_NAME 			= $row['singer_name'];
				$singer_IMG 			= m_get_img('Album',$row['singer_img']);
				$singer_INFO			= ($row['singer_info'])?m_text_tidy($row['singer_info']):'Chưa có';
				$playSinger_URL			= url_link($singer_ID,$singer_NAME,'PlaySinger');
				/// ALBUM ////
				$sql_album 			= "SELECT * FROM ".$tb_prefix."album WHERE album_singer = $id";
				$query_album 		= $mysql->query($sql_album);
					if($mysql->num_rows($query_album)) {
						while($row_album = $mysql->fetch_array($query_album)) {
							$album_ID 	 = $row_album['album_id'];
							$album_NAME  = $row_album['album_name'];
							
							$album_VIEWED= $row_album['album_viewed'];
							$album_IMG	 = m_get_img('Album',$row_album['album_img']);
							
							$album_URL	 = url_link($album_ID,$album_NAME,'Album');
							
							$album_HTML	.= "<a href=$album_URL><b>$album_NAME</b></a><br/><br/>";
						}
				}
				if(!$mysql->num_rows($query_album)) {
					$album_HTML			 = "<tr align=center><td width=100% align=center>Ca sĩ này chưa có Album</td></tr>";
				}
				#############
				## PHAN TRANG ##
				#############
				// CHECK TOTAL SONGS
				$num 					 = $mysql->query("SELECT * FROM ".$tb_prefix."data WHERE m_singer = $id");
				$total 					 = $mysql->num_rows($num);
				if (!$pg) $pg = 1;
				$m_per_page 			 = m_get_config("media_per_page");
				////// SONGS ////////
				$sql_song 				 = "SELECT * FROM ".$tb_prefix."data WHERE m_singer = $id LIMIT ".(($pg-1)*$m_per_page).",".$m_per_page;
				$query_song 			 = $mysql->query($sql_song);
					if($mysql->num_rows($query_song)) {
						while($row_song  = $mysql->fetch_array($query_song)) {
							switch ($row_song['m_type']) {
							case 1 : $media_type = 'music'; break;
							case 2 : $media_type = 'flash'; break;
							case 3 : $media_type = 'movie'; break;
						}
						$song_TYPE 		 = "<img src='/templates/".$_SESSION['current_tpl']."/img/media/type/$media_type.gif'>";
						$song_LYRIC 	 = ($row_song['m_lyric'])?"<img src='/templates/".$_SESSION['current_tpl']."/img/media/ok.gif'>":'';

						$song_ID 		 = $row_song['m_id'];
						$song_TITLE 	 = $row_song['m_title'];
												
						$song_VIEWED	 = $row_song['m_viewed'];
						$song_DOWNLOADED = $row_song['m_downloaded'];
						
						$song_URL		 = url_link($song_ID,$song_TITLE,'nhac-san');
						$user_ID = $row_song['m_poster'];
						$user_NAME =  m_get_data('USER',$user_ID);
						$song_TITLE = $row_song['m_title'];
						$song_TITLE1 = $song_TITLE;
						if($user_NAME == '')
							{
								$user_NAME = 'DJ Other';
							}
						$addp = 'addToPlaylist('.$song_ID.');return false;';	
						if (!$isLoggedIn){
							$addp = 'alert("Yêu cầu đăng nhập")';
						}
						$user_URL	= url_link($user_ID,$user_NAME,'User');
						$m_rate = $row_song['m_rating'];
						$m_rate_total = $row_song['m_rating_total'];
						if ($m_rate =='0') $current_star = 0;

						else $rater_rating = $m_rate / $m_rate_total;
						if ($rater_rating <= 0  ) $star = 0;
						if ($rater_rating >= 0.5) $star = 1;
						if ($rater_rating >= 1) $star = 2;
						if ($rater_rating >= 1.5) $star = 3;
						if ($rater_rating >= 2) $star = 4;
						if ($rater_rating >= 2.5) $star = 5;
						if ($rater_rating >= 3) $star = 6;
						if ($rater_rating >= 3.5) $star = 7;
						if ($rater_rating >= 4) $star = 8;
						if ($rater_rating >= 4.5) $star = 9;
						if ($rater_rating >= 5) $star = 10;
						$link		 	 = (m_get_config('url_type') == 0)?$mainURL."/index.php?go=singer&id=".$id."&pg=":$mainURL."/Singer/".$id."/".name_on_bar($singer_NAME)."/Page/";						
						$view_pages 	 = m_viewpages($total,$m_per_page,$pg,$link);
						$song_HTML .= "<li><p class='right'><span class='rate s_".$star."'><span><span><span><span><span></span></span></span></span></span></span><span class='add_pl'><a href='#' onclick='$addp' title='Add to Playlist'></a></span></p><p class='title'><a href='$song_URL' title='$song_TITLE'>$song_TITLE1</a></p><p class='user'>Đăng bởi: <a href='$user_URL'>$user_NAME</a> | <a href='$cat_URL'>$cat_NAME</a> | Lượt nghe: $song_VIEWED</p></li>";
						}
					}
					if(!$mysql->num_rows($query_song)) {
						$song_HTML 		 = "<tr align=center><td width=100%>Chưa có bài hát</td></tr>";
					}
include("templates/".$_SESSION['current_tpl']."/singer_info.html");
	}
}
if($id == "-1" || $id == '-2') {
				#############
				## PHAN TRANG ##
				#############
				// CHECK TOTAL SONGS
				$num 					 = $mysql->query("SELECT * FROM ".$tb_prefix."data WHERE m_singer = $id");
				$total 					 = $mysql->num_rows($num);
				if (!$pg) $pg = 1;
				$m_per_page 			 = m_get_config("media_per_page");
				////// SONGS ////////
				$sql_song 				 = "SELECT * FROM ".$tb_prefix."data WHERE m_singer = $id LIMIT ".(($pg-1)*$m_per_page).",".$m_per_page;
				$query_song 			 = $mysql->query($sql_song);
					if($mysql->num_rows($query_song)) {
						while($row_song  = $mysql->fetch_array($query_song)) {
							switch ($row_song['m_type']) {
								case 1 : $media_type = 'music'; break;
								case 2 : $media_type = 'flash'; break;
								case 3 : $media_type = 'movie'; break;
							}
							switch ($id) {
								case '-1' : $name = 'VN'; break;
								case '-2' : $name = 'QT'; break;
							}
						$song_TYPE 		 = "<img src='$tpl_link/img/media/type/$media_type.gif'>";
						$song_LYRIC 	 = ($row_song['m_lyric'])?"<img src='$tpl_link/img/media/ok.gif'>":'';

						$song_ID 		 = $row_song['m_id'];
						$song_TITLE 	 = $row_song['m_title'];
						
						$song_VIEWED	 = $row_song['m_viewed'];
						$song_DOWNLOADED = $row_song['m_downloaded'];
						
						$song_URL			 = url_link($song_ID,$song_TITLE,'nhac-san');

						$link		 	 = (m_get_config('url_type') == 0)?"/index.php?go=singer&id=".$id."&pg=":"/Singer/".$id."/Chua-biet-".$name."/Page/";
						$view_pages 	 = m_viewpages($total,$m_per_page,$pg,$link);
						$user_ID = $row_song['m_poster'];
						$user_NAME =  m_get_data('USER',$user_ID);
						$song_TITLE = $row_song['m_title'];
						$song_TITLE1 = $song_TITLE;
						if($user_NAME == '')
							{
								$user_NAME = 'DJ Other';
							}
						$addp = 'addToPlaylist('.$song_ID.');return false;';	
						if (!$isLoggedIn){
							$addp = 'alert("Yêu cầu đăng nhập")';
						}
						$user_URL	= url_link($user_ID,$user_NAME,'User');
						$m_rate = $row_song['m_rating'];
						$m_rate_total = $row_song['m_rating_total'];
						if ($m_rate =='0') $current_star = 0;

						else $rater_rating = $m_rate / $m_rate_total;
						if ($rater_rating <= 0  ) $star = 0;
						if ($rater_rating >= 0.5) $star = 1;
						if ($rater_rating >= 1) $star = 2;
						if ($rater_rating >= 1.5) $star = 3;
						if ($rater_rating >= 2) $star = 4;
						if ($rater_rating >= 2.5) $star = 5;
						if ($rater_rating >= 3) $star = 6;
						if ($rater_rating >= 3.5) $star = 7;
						if ($rater_rating >= 4) $star = 8;
						if ($rater_rating >= 4.5) $star = 9;
						if ($rater_rating >= 5) $star = 10;
						$song_HTML .= "<li><p class='right'><span class='rate s_".$star."'><span><span><span><span><span></span></span></span></span></span></span><span class='add_pl'><a href='#' onclick='$addp' title='Add to Playlist'></a></span></p><p class='title'><a href='$song_URL' title='$song_TITLE'>$song_TITLE1</a></p><p class='user'>Đăng bởi: <a href='$user_URL'>$user_NAME</a> | <a href='$cat_URL'>$cat_NAME</a> | Lượt nghe: $song_VIEWED</p></li>";
						}
					}
					if(!$mysql->num_rows($query_song)) {
						$song_HTML 		 = "<tr align=center><td width=100%>Chưa có bài hát</td></tr>";
					}
include("templates/".$_SESSION['current_tpl']."/singer_info.html");
}
if($play) {
	$sql 								= "SELECT * FROM ".$tb_prefix."singer WHERE singer_id = $play";
	$query 								= $mysql->query($sql);
	$r	 								= $mysql->fetch_array($query);
	$singer_ID 							= $r['singer_id'];
	$singer_NAME						= $r['singer_name'];
	$singer_IMG							= m_get_img('Album',$r['singer_img']);
	$singer_INFO 						= m_text_tidy($r['singer_info']);
	$singer_URL							= url_link($singer_ID,$singer_NAME,'Singer');							
	$url_play 							= $mainURL.'/asx.php?type=2&id='.$singer_ID;
	include("templates/".$_SESSION['current_tpl']."/play_singer.html");
}